import re
import requests
from bs4 import BeautifulSoup
import datetime

class HandleNews(object):
    def __init__(self):
        self.request = requests.Session()
        self.header={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36'
                     }
        self.newslist = ''

    def handle_list(self):
        handle_url = "https://www.chinanews.com/gn/2021/08-09/9539581.shtml"
        handle_news=self.handle_request(methon='GET',url=handle_url,head=self.header)
        print(handle_news.encoding)
        handle_news.encoding = 'utf-8'
        soup = BeautifulSoup(handle_news.content,'html.parser')
        # print(soup.find_all(class_="content"))

    def handle_list2(self):
        handle_url = "https://www.chinanews.com/scroll-news/news1.html"
        handle_news=self.handle_request(methon='GET',url=handle_url,head=self.header)
        print(handle_news.encoding)
        handle_news.encoding = 'utf-8'
        soup = BeautifulSoup(handle_news.content,'html.parser')
        # print(soup)
        A = soup.find_all(class_="dd_bt")[0]
        C = str(A)
        B = re.compile(r'/news/(.*).shtml')
        print(re.findall(B,C),A)
        print(datetime.datetime.now().month,datetime.datetime.now().day)
        print(datetime.datetime.now())

    def handle_request(self,methon,url,head,data=None , info=None):
        if methon == 'GET':
            handle_respone=self.request.get(url=url,headers=head)
        else:
            handle_respone=' '
        return handle_respone

if __name__ == '__main__':
    handle=HandleNews()
    # handle.handle_list()
    handle.handle_list2()